package br.com.cnpv.modelo.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import br.com.cnpv.modelo.acesso.idao.ICombustivelDAO;
import br.com.cnpv.modelo.entity.Combustivel;

public class CombustivelDAO implements ICombustivelDAO{

	@SuppressWarnings("unchecked")
	public List<Combustivel> buscar(Combustivel combustivel, Session session)
			throws HibernateException {
		Query query = session.getNamedQuery("Combustivel.buscar");
		query.setString("dsCombustivel", "%"+combustivel.getDsCombustivel()+"%");
		
		return query.list();
	}

	public void saveOrUpdate(Combustivel combustivel, Session session)
			throws HibernateException {
		session.merge(combustivel);
	}

	@SuppressWarnings("unchecked")
	public List<Combustivel> listar(Session session) throws HibernateException {
		Query query = session.getNamedQuery("Combustivel.listar");
		
		return query.list();
	}
}